package org.luojs.sorttest;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

/**
 * 随机遍历完列表
 */
public class ListRandomForeach {

    public static void main(String[] args) {

        List<String> list = new ArrayList<>();
        list.add("语文");
        list.add("数学");
        list.add("英语");
        list.add("物理");
        list.add("化学");
        list.add("历史");
        list.add("政治");

        List<String> randomList = list.stream().collect(Collectors.toList());

        Random random = new Random();
        for (int i = 0; i <= list.size() - 1; i++) {
            int ads = random.nextInt(randomList.size());
            String s = randomList.get(ads);
            System.out.println(s);
            randomList.remove(ads);
        }
    }
}
